package com.fanghuaiming.test.netty.c5.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import lombok.extern.slf4j.Slf4j;

/****
 * @description:
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2021/9/28 下午11:06
 *
 */
@Slf4j
public class TetsJdkFuture {

  public static void main(String[] args) throws ExecutionException, InterruptedException {
      ExecutorService service = Executors.newFixedThreadPool(2);
      Future<Integer> future = service.submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
              log.info("执行计算");
              Thread.sleep(1000);
              return 50;
          }
      });
      log.info("等待结果");
      Integer result = future.get();
      log.info("结果是:{}",result);
      service.shutdown();
  }
}
